import {de, STR} from "./STR";
import {http} from "./http";
import {UNIT} from "./UNIT";

export class user {

    constructor() {

    }

    async check() {

       // let userAccount = UNIT.GetValueFromCookie("userAccount");
        this.userAccount=UNIT.GetValueFromCookie("userAccount");//userAccount;
        this.sid=UNIT.GetValueFromCookie("sid");
        this.domainCode = UNIT.GetValueFromCookie("domainCode");
        this.userPassword=UNIT.GetValueFromCookie("userPassword");

        /*let response = await fetch(`/useris/service/getdetail?userAccount=${userAccount}`);

        let textArray = JSON.parse(await response.text());

        let newUserAccount=textArray[textArray.indexOf("userAccount") + 1];

        if(userAccount!==newUserAccount){
            response = await fetch(`/useris/service/getdetail?userAccount=${newUserAccount}`);
            textArray = JSON.parse(await response.text());
            userAccount=textArray[textArray.indexOf("userAccount") + 1];
        }

        /!*if (textArray[textArray.indexOf("rankId") + 1] !== "58") {
            delete this.userAccount;
            delete this.domainCode;
            Object.freeze(this);
            console.log(`%c${de(STR.GWYERROR)}`,"font-size:60px;");
            console.log(STR.BS);
            return false;
        }else {
            this.userAccount=userAccount;
            this.sid=data.match(/"sid":"([^"]+)"/)[1];
            this.domainCode = data.match(/"domainCode":"([^"]+)"/)[1];
        }*!/

        this.userAccount=userAccount;
        this.sid=UNIT.GetValueFromCookie("sid");
        this.domainCode = UNIT.GetValueFromCookie("domainCode");
        this.userPassword=UNIT.GetValueFromCookie("userPassword");*/

        return true;

    }

    /*async get_user_info(){
        let response = await http.get(`/useris/service/getdetail?userAccount=${this.userAccount}`);

        let textArray = JSON.parse(await response.text());
        this.domainCode=textArray[textArray.indexOf("domainCode") + 1];
        this.password=textArray[textArray.indexOf("userPassword") + 1];

        response=await http.get(`/bss/service/userService!doUserLogin.do?userAccount=${this.userAccount}&userPassword=${this.password}&code=2f56fe3477f774c4ece2b926070b6d0a`);
        let data=await response.json();
        this.sid=data.data.sid;
    }*/

}